package com.hysoft.common.result;

import io.swagger.v3.oas.annotations.media.Schema;

import java.util.List;

@Schema(name = "表格返回结果", description = "表格返回结果")
public class GridResult<D> {
    @Schema(description = "当前展示的页码")
    private Integer pageIndex;
    @Schema(description = "每页展示的条数")
    private Integer pageSize;
    @Schema(description = "总查询条数")
    private Integer total;
    @Schema(description = "总共分多少页")
    private Integer pageNum;
    @Schema(description = "具体页面展示的数据")
    private List<D> records;
    private GridResult(int pageIndex, int pageSize, int total, List<D> records) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.total = total;
        this.records = records;
        this.pageNum = total / pageSize + (total % pageSize > 0 ? 1 : 0);
    }

    public static GridResult<?> getInstance(int pageIndex, int pageSize, int total, List<?> records) {
        return new GridResult<>(pageIndex, pageSize, total, records);
    }

    public Integer getPageIndex() {
        return pageIndex;
    }

    public void setPageIndex(Integer pageIndex) {
        this.pageIndex = pageIndex;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public List<D> getRecords() {
        return records;
    }

    public void setRecords(List<D> records) {
        this.records = records;
    }
}
